<?php


namespace App\Server;


use Predis\Command\Redis\HKEYS;

class RedisServer
{
    //
    private static $instance;

    private $redis;

    /**
     * 用于初始化，构建对象被时调用
     * RedisServer constructor.
     */
    private function __construct()
    {
        $redis=new \Redis();
        $redis->connect(env('REDIS_HOST'),env('REDIS_PORT'));
        $redis->select(1);
        $this->redis=$redis;
    }

    /**
     *
     * 公共的静态方法 对外提供实例
     */
    public static function getInstance(){
        if (self::$instance){
            return self::$instance;
        } else {
            self::$instance=new self();
            return self::$instance;
        }
    }

    /**
     * 防止类外复制这类实例
     */
    public function __clone()
    {
        //
    }

    //
    public function exists($key){
        return $this->redis->exists($key);
    }

    public function rPush($key,$value)
    {
        return $this->redis->rPush($key,$value);
    }

    public function lPop($key){
        return $this->redis->lPop($key);
    }


    public function sAdd($key,$data)
    {
        return $this->redis->sAdd($key,$data);
    }

    public function sIsMember($key,$data)
    {
        return $this->redis->sIsMember($key,$data);
    }

    public function watch($key)
    {
        $this->redis->watch($key);
    }

    public function multi()
    {
        $this->redis->multi();
    }

    public function lLen($key)
    {
        return $this->redis->lLen($key);
    }

    public function exec()
    {
        return $this->redis->exec();
    }


}
